package com.xmg.server.goods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xmg.server.goods.mapper.SkuPropertyMapper;
import com.xmg.shop.api.domain.SkuProperty;
import com.xmg.shop.api.service.ISkuPropertyService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by KavenC on 2017/11/15.
 */
@Service
public class SkuPropertyServiceImpl implements ISkuPropertyService {
    @Autowired
    private SkuPropertyMapper skuPropertyMapper;

    @Override
    public List<SkuProperty> selectAll() {
        return skuPropertyMapper.selectAll();
    }

    @Override
    public SkuProperty selectByskuPropertyId(Long skuPropertyId) {
        return skuPropertyMapper.selectByPrimaryKey(skuPropertyId);
    }

    @Override
    public List<SkuProperty> selectByCatalogId(Long catalogId) {
        return skuPropertyMapper.selectByCatalogId(catalogId);
    }

    @Override
    public void delete(Long skuPropertyId) {
        skuPropertyMapper.deleteByPrimaryKey(skuPropertyId);
    }

    @Override
    public void save(SkuProperty skuProperty) {
        skuProperty.setSequence(0);
        skuPropertyMapper.insert(skuProperty);
    }

    @Override
    public void update(SkuProperty skuProperty) {
        SkuProperty property = this.skuPropertyMapper.selectByPrimaryKey(skuProperty.getId());
        property.setName(skuProperty.getName());
        property.setType(skuProperty.getType());
        this.skuPropertyMapper.updateByPrimaryKey(property);
    }
}
